package formularios;

import dao.LivroDAO;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import negocios.Livro;

public final class FormLivroPrincipal extends javax.swing.JFrame {

    DefaultTableModel tmLivro = new DefaultTableModel(null, new String[]{"Num", "Data", "Autor", "Titulo", "Ex", "Volume", "Local", "Editora", "Genero", "Tipo", "Ano_publicacao", "CDD", "CDU", "Obs", "Id_livro"});
    List<Livro> Livro; // autor = contato;
    ListSelectionModel lsmLivro;

    public FormLivroPrincipal() throws SQLException {
        initComponents();
        setExtendedState(MAXIMIZED_BOTH);
        listarLivro();
        jTF_idlivro.setEditable(false);
    }

    @SuppressWarnings({"unchecked", "CallToThreadDumpStack"})
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPPrincipal = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jB_pesquisa = new javax.swing.JButton();
        jTF_pesquisa = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTTabela_Livro = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jT_Num = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jT_Titulo = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jT_AUtor = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jT_Editora = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jT_Volume = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jT_Exemplo = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jT_Ano_Publicado = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jT_CDD = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jT_CDU = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jTF_obs = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jTF_tipo = new javax.swing.JTextField();
        jTF_idlivro = new javax.swing.JTextField();
        jT_Data = new javax.swing.JFormattedTextField();
        jLabel8 = new javax.swing.JLabel();
        jT_local = new javax.swing.JComboBox();
        jTF_genero = new javax.swing.JComboBox();
        jPanel3 = new javax.swing.JPanel();
        jB_novo = new javax.swing.JButton();
        jB_salvar = new javax.swing.JButton();
        jB_Excluir = new javax.swing.JButton();
        jB_sair = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("SGB (Sistema Gerenciador da Biblioteca)");

        jPPrincipal.setBackground(new java.awt.Color(204, 255, 204));
        jPPrincipal.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true), "Livros", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 18), new java.awt.Color(0, 102, 0))); // NOI18N

        jPanel1.setBackground(new java.awt.Color(204, 255, 204));

        jB_pesquisa.setBackground(new java.awt.Color(204, 255, 204));
        jB_pesquisa.setForeground(new java.awt.Color(0, 102, 0));
        jB_pesquisa.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Png/Figura1.PNG"))); // NOI18N
        jB_pesquisa.setText("Pesquisa");
        jB_pesquisa.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED, new java.awt.Color(0, 102, 0), java.awt.Color.white), new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 1, true)));
        jB_pesquisa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jB_pesquisaActionPerformed(evt);
            }
        });

        jTF_pesquisa.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTF_pesquisaKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTF_pesquisaKeyReleased(evt);
            }
        });

        jScrollPane1.setBackground(new java.awt.Color(153, 255, 153));
        jScrollPane1.setViewportBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 1, true));

        jTTabela_Livro.setBackground(new java.awt.Color(204, 255, 204));
        jTTabela_Livro.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 1, true));
        jTTabela_Livro.setFont(new java.awt.Font("Tahoma", 1, 12));
        jTTabela_Livro.setForeground(new java.awt.Color(0, 102, 0));
        jTTabela_Livro.setModel(tmLivro);
        jTTabela_Livro.setGridColor(new java.awt.Color(0, 102, 0));
        jTTabela_Livro.setInheritsPopupMenu(true);
        jTTabela_Livro.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        lsmLivro = jTTabela_Livro.getSelectionModel();
        lsmLivro.addListSelectionListener(new ListSelectionListener(){
            public void valueChanged(ListSelectionEvent e){
                if(! e.getValueIsAdjusting()){
                    JTTabelaLinhaSelecionada(jTTabela_Livro);
                }
            }
        }
    );
    jScrollPane1.setViewportView(jTTabela_Livro);

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1445, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addComponent(jTF_pesquisa, javax.swing.GroupLayout.DEFAULT_SIZE, 1350, Short.MAX_VALUE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jB_pesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap())))
    );
    jPanel1Layout.setVerticalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jTF_pesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jB_pesquisa))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 308, Short.MAX_VALUE))
    );

    jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jB_pesquisa, jTF_pesquisa});

    jPanel2.setBackground(new java.awt.Color(204, 255, 204));
    jPanel2.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 3, true));

    jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12));
    jLabel1.setText("Tomb.:");

    jT_Num.setFont(new java.awt.Font("Tahoma", 1, 12));
    jT_Num.setForeground(new java.awt.Color(0, 102, 0));
    jT_Num.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));

    jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12));
    jLabel2.setText("Data:");

    jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12));
    jLabel3.setText("Titulo:");

    jT_Titulo.setFont(new java.awt.Font("Tahoma", 1, 12));
    jT_Titulo.setForeground(new java.awt.Color(0, 102, 0));
    jT_Titulo.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));

    jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12));
    jLabel4.setText("Autor:");

    jT_AUtor.setFont(new java.awt.Font("Tahoma", 1, 12));
    jT_AUtor.setForeground(new java.awt.Color(0, 102, 0));
    jT_AUtor.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));
    jT_AUtor.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jT_AUtorActionPerformed(evt);
        }
    });

    jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12));
    jLabel5.setText("Editora:");

    jT_Editora.setFont(new java.awt.Font("Tahoma", 1, 12));
    jT_Editora.setForeground(new java.awt.Color(0, 102, 0));
    jT_Editora.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));

    jLabel6.setFont(new java.awt.Font("Tahoma", 1, 12));
    jLabel6.setText("Volume:");

    jT_Volume.setFont(new java.awt.Font("Tahoma", 1, 12));
    jT_Volume.setForeground(new java.awt.Color(0, 102, 0));
    jT_Volume.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));

    jLabel7.setFont(new java.awt.Font("Tahoma", 1, 12));
    jLabel7.setText("Exemplar:");

    jT_Exemplo.setFont(new java.awt.Font("Tahoma", 1, 12));
    jT_Exemplo.setForeground(new java.awt.Color(0, 102, 0));
    jT_Exemplo.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));

    jLabel9.setFont(new java.awt.Font("Tahoma", 1, 12));
    jLabel9.setText("Ano Publicado:");

    jT_Ano_Publicado.setFont(new java.awt.Font("Tahoma", 1, 12));
    jT_Ano_Publicado.setForeground(new java.awt.Color(0, 102, 0));
    jT_Ano_Publicado.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));

    jLabel10.setFont(new java.awt.Font("Tahoma", 1, 12));
    jLabel10.setText("CDD:");

    jT_CDD.setFont(new java.awt.Font("Tahoma", 1, 12));
    jT_CDD.setForeground(new java.awt.Color(0, 102, 0));
    jT_CDD.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));

    jLabel11.setFont(new java.awt.Font("Tahoma", 1, 12));
    jLabel11.setText("CDU:");

    jT_CDU.setFont(new java.awt.Font("Tahoma", 1, 12));
    jT_CDU.setForeground(new java.awt.Color(0, 102, 0));
    jT_CDU.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));

    jLabel12.setFont(new java.awt.Font("Tahoma", 1, 12));
    jLabel12.setText("Obs:");

    jTF_obs.setFont(new java.awt.Font("Tahoma", 1, 12));
    jTF_obs.setForeground(new java.awt.Color(0, 102, 0));
    jTF_obs.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));

    jLabel13.setFont(new java.awt.Font("Tahoma", 1, 12));
    jLabel13.setText("Genero:");

    jLabel14.setFont(new java.awt.Font("Tahoma", 1, 12));
    jLabel14.setText("Tipo:");

    jTF_tipo.setFont(new java.awt.Font("Tahoma", 1, 12));
    jTF_tipo.setForeground(new java.awt.Color(0, 102, 0));
    jTF_tipo.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));

    jTF_idlivro.setForeground(new java.awt.Color(0, 102, 0));
    jTF_idlivro.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jTF_idlivroActionPerformed(evt);
        }
    });

    jT_Data.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));
    jT_Data.setForeground(new java.awt.Color(0, 102, 0));
    try {
        jT_Data.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##-##-##")));
    } catch (java.text.ParseException ex) {
        ex.printStackTrace();
    }

    jLabel8.setFont(new java.awt.Font("Tahoma", 1, 12));
    jLabel8.setText("UF:");

    jT_local.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "UF?", "AC", "AL", "AP", "AM", "BA", "CE", "DF", "ES", "GO", "MA", "MT", "MS", "MG", "PA", "PB", "PR", "PE", "PI", "RJ", "RN", "RS", "RO", "RR", "SC", "SP", "SE", "TO" }));
    jT_local.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));

    jTF_genero.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Genero?", "Didático", "Para-didático" }));
    jTF_genero.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));

    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(
        jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel2Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addComponent(jLabel1)
                .addComponent(jLabel3)
                .addComponent(jLabel9)
                .addComponent(jLabel12)
                .addComponent(jLabel4)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel8)))
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGap(12, 12, 12)
                    .addComponent(jTF_obs, javax.swing.GroupLayout.PREFERRED_SIZE, 674, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jTF_idlivro, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addGap(10, 10, 10)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jT_Num, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jT_Titulo, javax.swing.GroupLayout.PREFERRED_SIZE, 339, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jT_AUtor, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addGap(12, 12, 12)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jT_Ano_Publicado, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jT_Data, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jT_local, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel13, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel14, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel11, javax.swing.GroupLayout.Alignment.TRAILING))
                    .addGap(22, 22, 22)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jTF_genero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                                    .addComponent(jT_CDU, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(1, 1, 1))
                                .addComponent(jT_CDD, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING))
                            .addGap(18, 18, 18)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jT_Volume, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jT_Exemplo, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(72, 72, 72))
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jT_Editora, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE)
                                .addComponent(jTF_tipo, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE))
                            .addGap(69, 69, 69)))))
            .addContainerGap())
    );

    jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jT_Data, jT_Num});

    jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jT_Exemplo, jT_Volume});

    jPanel2Layout.setVerticalGroup(
        jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel2Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel1)
                .addComponent(jT_Num, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(jT_Titulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jT_AUtor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel4))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel8)
                        .addComponent(jT_local, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(jT_Data, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel9)
                        .addComponent(jT_Ano_Publicado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addComponent(jLabel14)
                            .addGap(7, 7, 7))
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel13)
                                .addComponent(jTF_genero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jTF_tipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(6, 6, 6)))
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel5)
                        .addComponent(jT_Editora, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel10)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel6)
                                    .addComponent(jT_Volume, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel11)
                                .addComponent(jLabel7)
                                .addComponent(jT_Exemplo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addComponent(jT_CDD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jT_CDU, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGap(5, 5, 5)))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel12)
                .addComponent(jTF_obs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jTF_idlivro, javax.swing.GroupLayout.PREFERRED_SIZE, 12, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addContainerGap())
    );

    jPanel2Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jTF_tipo, jT_AUtor, jT_Ano_Publicado, jT_Data, jT_Editora, jT_Exemplo, jT_Num, jT_Titulo});

    jPanel3.setBackground(new java.awt.Color(204, 255, 204));
    jPanel3.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 3, true));

    jB_novo.setBackground(new java.awt.Color(204, 255, 204));
    jB_novo.setFont(new java.awt.Font("Tahoma", 1, 14));
    jB_novo.setForeground(new java.awt.Color(0, 102, 0));
    jB_novo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Png/Figura3.png"))); // NOI18N
    jB_novo.setText("Novo");
    jB_novo.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createEtchedBorder(new java.awt.Color(0, 102, 0), java.awt.Color.white), new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 1, true)));
    jB_novo.setFocusable(false);
    jB_novo.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jB_novoActionPerformed(evt);
        }
    });

    jB_salvar.setBackground(new java.awt.Color(204, 255, 204));
    jB_salvar.setFont(new java.awt.Font("Tahoma", 1, 14));
    jB_salvar.setForeground(new java.awt.Color(0, 102, 0));
    jB_salvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Png/Figura7.png"))); // NOI18N
    jB_salvar.setText("Salvar");
    jB_salvar.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createEtchedBorder(new java.awt.Color(0, 102, 0), java.awt.Color.white), new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 1, true)));
    jB_salvar.setFocusable(false);
    jB_salvar.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jB_salvarActionPerformed(evt);
        }
    });

    jB_Excluir.setBackground(new java.awt.Color(204, 255, 204));
    jB_Excluir.setFont(new java.awt.Font("Tahoma", 1, 14));
    jB_Excluir.setForeground(new java.awt.Color(0, 102, 0));
    jB_Excluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Png/figura0.png"))); // NOI18N
    jB_Excluir.setText("Excluir");
    jB_Excluir.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createEtchedBorder(new java.awt.Color(0, 102, 0), java.awt.Color.white), new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 1, true)));
    jB_Excluir.setFocusable(false);
    jB_Excluir.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jB_ExcluirActionPerformed(evt);
        }
    });

    jB_sair.setBackground(new java.awt.Color(204, 255, 204));
    jB_sair.setFont(new java.awt.Font("Tahoma", 1, 14));
    jB_sair.setForeground(new java.awt.Color(0, 102, 0));
    jB_sair.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Png/Figura6.png"))); // NOI18N
    jB_sair.setText("Voltar");
    jB_sair.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createEtchedBorder(new java.awt.Color(0, 102, 0), java.awt.Color.white), new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 1, true)));
    jB_sair.setFocusable(false);
    jB_sair.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jB_sairActionPerformed(evt);
        }
    });

    javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
    jPanel3.setLayout(jPanel3Layout);
    jPanel3Layout.setHorizontalGroup(
        jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel3Layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jB_sair, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jB_novo, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jB_salvar, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jB_Excluir, javax.swing.GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
            .addContainerGap())
    );
    jPanel3Layout.setVerticalGroup(
        jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER, false)
                .addComponent(jB_salvar, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jB_Excluir, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jB_novo, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jB_sair, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addContainerGap())
    );

    jPanel3Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jB_Excluir, jB_novo, jB_sair, jB_salvar});

    javax.swing.GroupLayout jPPrincipalLayout = new javax.swing.GroupLayout(jPPrincipal);
    jPPrincipal.setLayout(jPPrincipalLayout);
    jPPrincipalLayout.setHorizontalGroup(
        jPPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPPrincipalLayout.createSequentialGroup()
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addContainerGap())
        .addGroup(jPPrincipalLayout.createSequentialGroup()
            .addGap(314, 314, 314)
            .addGroup(jPPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 826, Short.MAX_VALUE))
            .addGap(325, 325, 325))
    );
    jPPrincipalLayout.setVerticalGroup(
        jPPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPPrincipalLayout.createSequentialGroup()
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGap(18, 18, 18)
            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap())
    );

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(jPPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(jPPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    );

    pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jB_novoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jB_novoActionPerformed
        limpadados();


    }//GEN-LAST:event_jB_novoActionPerformed

    private void jB_salvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jB_salvarActionPerformed
        String iaa = String.valueOf(jTF_idlivro.getText());
        if (verificaDados()) {
            if ("".equals(iaa)) {
                try {
                    cadastrarLivro();
                    listarLivro();
                    limpadados();
                } catch (SQLException ex) {
                    Logger.getLogger(FormLivroPrincipal.class.getName()).log(Level.SEVERE, null, ex);
                }
            } else {
                try {
                    alteraLivro();
                    listarLivro();
                    limpadados();
                } catch (SQLException ex) {
                    Logger.getLogger(FormLivroPrincipal.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        } else {

            JOptionPane.showMessageDialog(null, "Campos não preenchidos");
        }

    }//GEN-LAST:event_jB_salvarActionPerformed

    private void jB_ExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jB_ExcluirActionPerformed
        try {
            excluirLivro();
            listarLivro();// TODO add your handling code here:
        } catch (SQLException ex) {
            Logger.getLogger(FormLivroPrincipal.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jB_ExcluirActionPerformed

    private void jB_sairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jB_sairActionPerformed
        dispose();

    }//GEN-LAST:event_jB_sairActionPerformed

    private void jTF_idlivroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTF_idlivroActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTF_idlivroActionPerformed

    private void jB_pesquisaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jB_pesquisaActionPerformed
        try {
            listarLivro();
        } catch (SQLException ex) {
            Logger.getLogger(FormLivroPrincipal.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jB_pesquisaActionPerformed

    private void jTF_pesquisaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTF_pesquisaKeyPressed
    }//GEN-LAST:event_jTF_pesquisaKeyPressed

    private void jT_AUtorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jT_AUtorActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jT_AUtorActionPerformed

    private void jTF_pesquisaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTF_pesquisaKeyReleased
        try {
            listarLivro();
        } catch (SQLException ex) {
            Logger.getLogger(FormLivroPrincipal.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_jTF_pesquisaKeyReleased
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jB_Excluir;
    private javax.swing.JButton jB_novo;
    private javax.swing.JButton jB_pesquisa;
    private javax.swing.JButton jB_sair;
    private javax.swing.JButton jB_salvar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPPrincipal;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JComboBox jTF_genero;
    private javax.swing.JTextField jTF_idlivro;
    private javax.swing.JTextField jTF_obs;
    private javax.swing.JTextField jTF_pesquisa;
    private javax.swing.JTextField jTF_tipo;
    private javax.swing.JTable jTTabela_Livro;
    private javax.swing.JTextField jT_AUtor;
    private javax.swing.JTextField jT_Ano_Publicado;
    private javax.swing.JTextField jT_CDD;
    private javax.swing.JTextField jT_CDU;
    private javax.swing.JFormattedTextField jT_Data;
    private javax.swing.JTextField jT_Editora;
    private javax.swing.JTextField jT_Exemplo;
    private javax.swing.JTextField jT_Num;
    private javax.swing.JTextField jT_Titulo;
    private javax.swing.JTextField jT_Volume;
    private javax.swing.JComboBox jT_local;
    // End of variables declaration//GEN-END:variables

    protected void listarLivro() throws SQLException {
        LivroDAO dao = new LivroDAO();
        Livro = dao.Buscar(jTF_pesquisa.getText() + "%");
        mostraPesquisa(Livro);


    }

    private void mostraPesquisa(List<Livro> Livro) {
        while (tmLivro.getRowCount() > 0) {
            tmLivro.removeRow(0);
        }
        if (Livro.isEmpty()) {
        } else {
            String[] linha = new String[]{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null};
            for (int i = 0; i < Livro.size(); i++) {
                tmLivro.addRow(linha);
                tmLivro.setValueAt(Livro.get(i).getNum(), i, 0);
                tmLivro.setValueAt(Livro.get(i).getData(), i, 1);
                tmLivro.setValueAt(Livro.get(i).getAutor(), i, 2);
                tmLivro.setValueAt(Livro.get(i).getTitulo(), i, 3);
                tmLivro.setValueAt(Livro.get(i).getEx(), i, 4);
                tmLivro.setValueAt(Livro.get(i).getVolume(), i, 5);
                tmLivro.setValueAt(Livro.get(i).getLocal(), i, 6);
                tmLivro.setValueAt(Livro.get(i).getEditora(), i, 7);
                tmLivro.setValueAt(Livro.get(i).getGenero(), i, 8);
                tmLivro.setValueAt(Livro.get(i).getTipo(), i, 9);
                tmLivro.setValueAt(Livro.get(i).getAno_publicacao(), i, 10);
                tmLivro.setValueAt(Livro.get(i).getCDD(), i, 11);
                tmLivro.setValueAt(Livro.get(i).getCDU(), i, 12);
                tmLivro.setValueAt(Livro.get(i).getObs(), i, 13);
                tmLivro.setValueAt(Livro.get(i).getId(), i, 14);
            }
        }
    }

    private void JTTabelaLinhaSelecionada(JTable tabela) {
        if (jTTabela_Livro.getSelectedRow() > -1) {
            jT_Num.setText(String.valueOf(Livro.get(tabela.getSelectedRow()).getNum()));
            jT_Data.setText((Livro.get(tabela.getSelectedRow()).getData()));
            jT_AUtor.setText((Livro.get(tabela.getSelectedRow()).getAutor()));
            jT_Titulo.setText((Livro.get(tabela.getSelectedRow()).getTitulo()));
            jT_Exemplo.setText(String.valueOf(Livro.get(tabela.getSelectedRow()).getEx()));
            jT_Volume.setText(String.valueOf(Livro.get(tabela.getSelectedRow()).getVolume()));
            jT_local.setSelectedItem((Livro.get(tabela.getSelectedRow()).getLocal()));
            jT_Editora.setText((Livro.get(tabela.getSelectedRow()).getEditora()));
            jTF_genero.setSelectedItem((Livro.get(tabela.getSelectedRow()).getGenero()));
            jTF_tipo.setText((Livro.get(tabela.getSelectedRow()).getTipo()));
            jT_Ano_Publicado.setText((Livro.get(tabela.getSelectedRow()).getAno_publicacao()));
            jT_CDD.setText(String.valueOf(Livro.get(tabela.getSelectedRow()).getCDD()));
            jT_CDU.setText(String.valueOf(Livro.get(tabela.getSelectedRow()).getCDU()));
            jTF_obs.setText((Livro.get(tabela.getSelectedRow()).getObs()));
            jTF_idlivro.setText(String.valueOf(Livro.get(tabela.getSelectedRow()).getId()));

        } else {
            limpadados();

        }
    }

    public boolean verificaDados() {
        if (!jT_Num.getText().equals("") && !jT_Titulo.getText().equals("") && !jT_AUtor.getText().equals("") && !jT_CDD.getText().equals("") && !jT_CDU.getText().equals("") && !jT_Data.getText().equals("") && !jT_Editora.getText().equals("") && !jT_Exemplo.getText().equals("") && !jT_local.getSelectedItem().equals("UF?")) {
            return true;
        } else {
            return false;
        }
    }

    public void alteraLivro() throws SQLException {
        if (jTTabela_Livro.getSelectedRow() > -1) {
            if (verificaDados()) {
                Livro c1 = new Livro();
                LivroDAO dao = new LivroDAO();

                c1.setId(Integer.parseInt(jTF_idlivro.getText()));
                c1.setNum(Integer.parseInt(jT_Num.getText()));
                c1.setData(jT_Data.getText());
                c1.setAutor(jT_AUtor.getText());
                c1.setTitulo(jT_Titulo.getText());
                c1.setEx(Integer.parseInt(jT_Exemplo.getText()));
                c1.setVolume(Integer.parseInt(jT_Volume.getText()));
                c1.setLocal((String) jT_local.getSelectedItem());
                c1.setEditora(jT_Editora.getText());
                c1.setGenero((String) jTF_genero.getSelectedItem());
                c1.setTipo(jTF_tipo.getText());
                c1.setAno_publicacao(jT_Ano_Publicado.getText());
                c1.setCDD(Long.parseLong(jT_CDD.getText()));
                c1.setCDU(Long.parseLong(jT_CDU.getText()));
                c1.setObs(jTF_obs.getText());
                dao.altera(c1);
            }
        }
    }

    public void desabilitaDados() {
        jTF_idlivro.setEditable(false);
    }

    private void excluirLivro() throws SQLException {
        int resp = JOptionPane.showConfirmDialog(this, "Deseja realmente excluir este contato?",
                "Confirmação", JOptionPane.YES_NO_OPTION);

        if (resp == JOptionPane.YES_NO_OPTION) {
            LivroDAO dao = new LivroDAO();

            dao.exclui(Livro.get(jTTabela_Livro.getSelectedRow()));
            mostraPesquisa(Livro);

        }
    }

    private void cadastrarLivro() throws SQLException {
        Livro a = new Livro();
        a.setNum(Integer.parseInt(jT_Num.getText()));
        a.setData(jT_Data.getText());
        a.setAutor(jT_AUtor.getText());
        a.setTitulo(jT_Titulo.getText());
        a.setEx(Integer.parseInt(jT_Exemplo.getText()));
        a.setVolume(Integer.parseInt(jT_Volume.getText()));
        a.setLocal((String) jT_local.getSelectedItem());
        a.setEditora(jT_Editora.getText());
        a.setGenero((String) jTF_genero.getSelectedItem());
        a.setTipo(jTF_tipo.getText());
        a.setAno_publicacao(jT_Ano_Publicado.getText());
        a.setCDD(Long.parseLong(jT_CDD.getText()));
        a.setCDU(Long.parseLong(jT_CDU.getText()));
        a.setObs(jTF_obs.getText());
        LivroDAO dao = new LivroDAO();
        dao.adicionar(a);
    }

    public void limpadados() {
        jTF_idlivro.setText("");
        jT_Num.setText("");
        jT_Data.setText("");
        jT_AUtor.setText("");
        jT_Titulo.setText("");
        jT_Exemplo.setText("");
        jT_Volume.setText("");
        jT_local.setSelectedItem("UF?");
        jT_Editora.setText("");
        jTF_genero.setSelectedItem("Genero?");
        jTF_tipo.setText("");
        jT_Ano_Publicado.setText("");
        jT_CDD.setText("");
        jT_CDU.setText("");
        jTF_obs.setText("");
    }
}
